import { getToken } from '@/utils/auth'
import axios from 'axios'

const URL = process.env.VUE_APP_BASE_API
// const httpService = new HttpUtils(URL).getService()
// 请求拦截器
// 创建axios 实例
const httpService = axios.create({
  baseURL: URL,
  timeout: 30000,
  headers: {
    'Cache-Control': 'no-cache',
    'Content-Type': 'application/json;charset=utf-8'
  }
})
// httpService.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
httpService.interceptors.request.use(
  config => {
    const isToken = (config.headers || {}).isToken === false
    if (getToken() && !isToken) {
      config.headers['Authorization'] = 'url_token ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
// 响应拦截器
httpService.interceptors.response.use(
  res => {
    // 获取错误信息
    return res
  },
  error => {
    console.log('err' + error)
    return Promise.reject(error)
  }
)
export default httpService

